package com.amos.muexamclient.sys.service.dto;


import com.alibaba.fastjson.JSONObject;
import com.amos.core.PageDTO;
import com.amos.muexamclient.sys.entity.SysUserEntity;
import com.amos.muexamcore.core.MuEntity;
import com.amos.muexamcore.core.MuField;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * Copyright © 2018 五月工作室. All rights reserved.
 *
 * @Package com.amos.muexamclient.service.dto
 * @ClassName SysUserDTO
 * @Description TODO
 * @Author Amos
 * @Modifier
 * @Date 2020-03-21 22:08:15
 * @Version 1.0
 **/
@MuEntity(table = "sys_user", entity = SysUserEntity.class)
@Data
public class SysUserDTO extends PageDTO implements Serializable {

    private static final long serialVersionUID = 4238998363894552782L;
    @MuField(remark = "头像地址", type = "varchar", length = 100, column = "avatar")
    private String avatar;

    @MuField(remark = "创建者", type = "varchar", length = 64, column = "create_by")
    private String createBy;

    @MuField(remark = "用户邮箱", type = "varchar", length = 50, column = "email")
    private String email;

    @MuField(remark = "用户组ID", type = "varchar", length = 32, column = "group_id")
    private String deptId;

    @MuField(remark = "最后登陆时间", type = "datetime", column = "login_date")
    private Date loginDate;

    @MuField(remark = "最后登陆IP", type = "varchar", length = 50, column = "login_ip")
    private String loginIp;

    @MuField(remark = "用户昵称", type = "varchar", length = 30, column = "nick_name")
    private String nickName;

    @MuField(remark = "密码", type = "varchar", length = 100, column = "password")
    private String password;

    @MuField(remark = "手机号码", type = "varchar", length = 11, column = "phonenumber")
    private String phonenumber;

    @MuField(remark = "备注", type = "varchar", length = 500, column = "remark")
    private String remark;

    @MuField(remark = "用户性别（0男 1女 2未知）", type = "tinyint", column = "sex")
    private Boolean sex;

    @MuField(remark = "帐号状态（1正常 0停用）", type = "tinyint", column = "status")
    private Boolean status;

    @MuField(remark = "更新者", type = "varchar", length = 64, column = "update_by")
    private String updateBy;

    @MuField(remark = "更新时间", type = "datetime", column = "update_time")
    private Date updateTime;

    @MuField(remark = "用户账号", type = "varchar", length = 30, column = "user_name")
    private String userName;

    @MuField(remark = "用户类型（00系统用户）", type = "varchar", length = 2, column = "user_type")
    private String userType;

    /**
     * 角色对象
     */
    private List<SysRoleDTO> roles;

    /**
     * 角色组
     */
    private String[] roleIds;

    /**
     * 岗位组
     */
    private String[] postIds;

    public boolean isAdmin() {
        return isAdmin(this.getId());
    }

    private Date beginTime;
    private Date endTime;

    public static boolean isAdmin(String userId) {
        return userId != null && "1" == userId;
    }

    @Override
    public String toString() {
        return JSONObject.toJSONString(this);
    }
}
